<%-- 
    Document   : attendanceTable
    Created on : 2019-7-26, 8:02:09
    Author     : dusin
--%>

<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.dusin.teachassistdbservice.serviceimpl.GeneralService"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="../../js/jquery/themes/default/easyui.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/icon.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/color.css" type="text/css" />
        <link rel="stylesheet" href="../../css/demo.css" type="text/css" />
        <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>
        <script type="text/javascript">
            var detail=[];
            $(document).ready(function() {
                var columns = [ {field:"no", width:"50",title:'序号'},
                                {field:"studentno", width:"100",title:'学号'},
                                {field: "name" ,width:"150",title:'姓名'}];
                <% String nos="" ;
                    Integer teachclassId = (Integer)session.getAttribute("teachclassid");
                    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
                    GeneralService instance = (GeneralService) context.getBean("generalService");
                    nos = instance.findLabNos(teachclassId);
                %>     
                detail=<%=nos%>;
                for(var i=1;i<detail.length+1;i++){
                    var r = {field:'no'+i,width:"50",title:i,formatter:formatterAttendanceStatus,
                        editor:{
                            type:'combobox',
                            options:{
                                valueField:'id',
                                textField:'name',
                                fit:true,                                
                                method:'get',
                                url:'../data/attendancetype.json',
                                required:true
                            }
                        }  
                    }
                    columns.push(r);
                }
                columns.push({field:"avg", width:"50",title:'平均分',formatter:formatterAverage});
                $('#dgAttendanceTable').datagrid({
                    url:'../../servlet/lab/GetLabTable',
                    columns:[columns],
                    fitColumns:true,
                    height:($(window).height()-40)+'px',
                    title:'${courseName}'+'->实验成绩记录表'  ,
                    singleSelect:true,
                    queryParams:{attendanceId:attendanceId},
                });
            });
        </script>
    </head>
    <body>       
        <table id="dgAttendanceTable"></table>
        <script type="text/javascript">
            var teachclassid = '<%=session.getAttribute("teachclassid")%>'
            var courseName = '<%=session.getAttribute("courseName")%>'
            var attendanceId = '<%=request.getParameter("attendanceId")%>';
            function formatterAttendanceStatus(value, row){
                if(value==0){   //这里value的类型是String，不能用‘===’三等号
                    return '<span style="color:green;">'+'✔'+'</span>';
                    
                }else if(value==100){
                    return 'A+';
                }else if(value==95){
                    return 'A';
                }else if(value==90){
                    return 'B+';
                }else if(value==85){
                    return 'B';
                }else if(value==80){
                    return 'C+';
                }else if(value==75){
                    return 'C';
                }else if(value==70){
                    return 'D+';
                }else if(value==65){
                    return 'D';
                }else if(value==60){
                    return 'E+';
                }else if(value>0&&value<60){
                    return 'F';
                }else{
                   return '<span style="color:red;">'+'✖'+'</span>';
                }                
            }
            function formatterAverage(value, row){
                var average = 0.0;
                var sum = 0.0;
                for(var i=0;i<detail.length;i++){
                    if(row['no'+detail[i]]==undefined||row['no'+detail[i]]==-1
                            ||row['no'+detail[i]]==null||row['no'+detail[i]]=="")                    
                        sum+= 0;
                    else{
                        sum+=row['no'+detail[i]];
                    }
                }
                if(detail.length==0){
                    average=0;
                }else{
                    average=sum/detail.length;
                }
                
                if(average<60){
                    return '<span style="color:red;">'+Math.round(average)+'</span>';
                }else{
                    return Math.round(average);
                }
            }
        </script>
    </body>
</html>
